package com.ynet.eq.haiqing.module.mqtt.impl;

import com.alibaba.fastjson.JSON;
import com.ynet.eq.mqtt.consumer.MqttConsumer;
import com.ynet.eq.haiqing.module.bean.MqttAddPersonsBaseReq;
import com.ynet.eq.haiqing.module.bean.MqttBaseReq;
import com.ynet.eq.haiqing.module.mqtt.MqttClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author 胡超雄
 * @date 2021/7/1 10:58
 * @desc
 */
@Service
@Slf4j
public class MqttClientServiceImpl implements MqttClientService {

    @Value("${mqttParms.publish.topic}") // mqtt/face/
    private String topic_name;

    @Override
    public void doExecute(MqttBaseReq req) {
        String topicName = topic_name + req.getId();
        log.debug("开始发布话题------话题→" + topicName);
        String message = JSON.toJSONString(req);
        log.debug("话题message:" + message);
        MqttConsumer.publish(topicName, message);
    }

    @Override
    public void doExecute(MqttAddPersonsBaseReq req) {
        String topicName = topic_name + req.getId();
        log.debug("开始发布话题------话题→" + topicName);
        String message = JSON.toJSONString(req);
        log.debug("话题message:" + message);
        MqttConsumer.publish(topicName, message);
    }
}
